package com.tao.demo.service.impl;

import com.baomidou.mybatisplus.core.conditions.query.QueryWrapper;
import com.github.yulichang.base.MPJBaseServiceImpl;
import com.tao.demo.domain.entity.WaterQuality;
import com.tao.demo.mapper.WaterQualityMapper;
import com.tao.demo.service.WaterQualityService;
import org.springframework.stereotype.Service;

import java.util.List;
import java.util.Map;

/**
 * <p>
 * 断面水质数据表 服务实现类
 * </p>
 *
 * @author LiTao
 * @since 2024-04-23
 */
@Service
public class WaterQualityServiceImpl extends MPJBaseServiceImpl<WaterQualityMapper, WaterQuality> implements WaterQualityService {
  
  @Override
  public List<Map<String, Object>> waterQualityCategoryDistribution(String province) {
    QueryWrapper<WaterQuality> wrapper = new QueryWrapper<WaterQuality>()
      .select("count(*) as count", "province", "water_quality_category")
      .eq("province", province)
      .isNotNull("water_quality_category")
      .groupBy("province", "water_quality_category");
    return baseMapper.selectMaps(wrapper);
  }
  
  @Override
  public List<Map<String, Object>> waterTemperatureChange() {
    QueryWrapper<WaterQuality> wrapper = new QueryWrapper<WaterQuality>()
      .select("province", "avg(water_temperature) as water_temperature")
      .groupBy("province");
    return baseMapper.selectMaps(wrapper);
  }
  
  @Override
  public List<Map<String, Object>> phDistribution() {
    QueryWrapper<WaterQuality> wrapper = new QueryWrapper<WaterQuality>()
      .select("province", "monitoring_time", "avg(pH) as pH")
      .groupBy("province", "monitoring_time");
    return baseMapper.selectMaps(wrapper);
  }
  
  @Override
  public List<Map<String, Object>> relevance() {
    QueryWrapper<WaterQuality> wrapper = new QueryWrapper<WaterQuality>()
      .select("dissolved_oxygen", "conductivity");
    return baseMapper.selectMaps(wrapper);
  }
  
  @Override
  public List<Map<String, Object>> turbidityDistribution() {
    QueryWrapper<WaterQuality> wrapper = new QueryWrapper<WaterQuality>()
    .select("province", "avg(turbidity) as turbidity")
    .groupBy("province");
    return baseMapper.selectMaps(wrapper);
  }
  
  
}
